define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'assistant/assistant_order/index' + location.search,
                    add_url: 'assistant/assistant_order/add',
                    edit_url: 'assistant/assistant_order/edit',
                    del_url: 'assistant/assistant_order/del',
                    multi_url: 'assistant/assistant_order/multi',
                    import_url: 'assistant/assistant_order/import',
                    table: 'assistant_order',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                fixedColumns: true,
                fixedRightNumber: 1,
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'assist.name', title: __('助教')},
                        {field: 'assist.mobile', title: __('助教电话')},
                        {field: 'user.mobile', title: __('用户手机号')},
                        {field: 'shop.name', title: __('预定店铺')},
                        {field: 'order_no', title: __('订单号'), operate: 'LIKE'},
                        {field: 'start_time', title: __('开始时间'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'end_time', title: __('结束时间'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'amount', title: __('订单金额'), operate:'BETWEEN'},
                        {field: 'pay_amount', title: __('支付金额'), operate:'BETWEEN'},
                        {field: 'create_time', title: __('时间'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'status', title: __('状态'), searchList: {"paying":__('待支付'),"payed":__('待接单'),"taked":__('已接单'),"doing":__('进行中'),"done":__('已完成'),"refund":__('已退款')}, formatter: Table.api.formatter.status},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate,
                            buttons:[
                                {
                                    name: 'list',
                                    title: __('退款'),
                                    text: '退款',
                                    classname: 'btn btn-xs btn-primary btn-dialog',
                                    url:function (row) {
                                        return "assistant/assistant_order/refund?ids=" + row.id;
                                    }
                                },
                            ],
                        }
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        refund:function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
